package cn.t.enums;

import cn.t.core.enums.Enumer;
import cn.t.core.enums.base.CommonEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author l
 */
@Enumer
@Getter
@AllArgsConstructor
public enum TimeLimitTypeEnum implements CommonEnum<Integer, String> {

    NO_LIMIT(-1,"不限"),
    EVERY_DAY(1,"每天"),
    WEEKLY(2,"每周"),
    EVERY_MONTH(3,"每月"),
    SEMI_ANNUAL(4,"每半年"),
    EVERY_YEAR(5,"每年"),
    EVERY_HOUR(6,"每小时");
    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;
    public static  String getNameByCode(Integer code){
        return Objects.isNull(code) ? null : Objects.requireNonNull(Arrays.stream(TimeLimitTypeEnum.values()).filter(item -> item.getCode().equals(code)).findFirst().orElse(null)).getName();
    }
    public static  TimeLimitTypeEnum getEnum(Integer code){
        return Objects.isNull(code) ? null : Objects.requireNonNull(Arrays.stream(TimeLimitTypeEnum.values()).filter(item -> item.getCode().equals(code)).findFirst().orElse(null));
    }

}
